import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import { type } from 'os';
import { JwtAuthGuard } from 'src/common/jwt/JwtAuthGuard';
import { HttpReslut } from 'src/common/result/http-reslut';
import {
  GetUserMessage,
  ResultUserMessageModel,
} from './dto/getUserMessage.dto';
import { MessageUserDto } from './dto/messageUser.dto';
import { SendMessage } from './dto/sendMessage.dto';
import { UserMessageService } from './user-message.service';

@ApiBearerAuth()
@UseGuards(new JwtAuthGuard())
@ApiTags('用户消息')
@Controller('userMessage')
export class UserMessageController {
  constructor(private readonly userMessageService: UserMessageService) {}

  @Get(':userId')
  async getMessageUserList(@Param('userId') userId: string) {
    const result = await this.userMessageService.getMessageUserList(userId);
    return new HttpReslut<MessageUserDto[]>(result);
  }

  @Post()
  @ApiOperation({
    summary: '获取用户聊天记录',
  })
  @ApiBody({
    type: GetUserMessage,
  })
  async getUserMessage(
    @Body('userId') userId: string,
    @Body('friendId') friendId: string,
  ) {
    let reslut = await this.userMessageService.getUserMessageList(
      userId,
      friendId,
    );
    return new HttpReslut<ResultUserMessageModel>(reslut);
  }

  @Post('/sendMessage')
  @ApiOperation({
    summary: '发送消息',
  })
  @ApiBody({
    type: SendMessage,
  })
  async sendMessage(@Body() body: SendMessage) {
    await this.userMessageService.sendMessage(body);
    return new HttpReslut<boolean>(true);
  }
}
